package com.harmony.pilot.knowledge.entity;

import lombok.Data;
import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * GN构建目标和源文件映射
 * 记录BUILD.gn中的target与其包含的源文件(.h/.cpp)的对应关系
 */
@Data
@Entity
@Table(name = "gn_source_mapping", indexes = {
    @Index(name = "idx_gn_target_id", columnList = "gn_target_id"),
    @Index(name = "idx_source_file", columnList = "source_file_path"),
    @Index(name = "idx_gn_file", columnList = "gn_file_path"),
    @Index(name = "idx_target_name", columnList = "target_name")
})
public class GnSourceMapping {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /** GN Target ID（关联到gn_target表） */
    @Column(name = "gn_target_id", nullable = false)
    private Long gnTargetId;
    
    /** 源文件路径（.h或.cpp文件的相对路径） */
    @Column(name = "source_file_path", nullable = false, length = 1000)
    private String sourceFilePath;
    
    /** 源文件类型：HEADER/SOURCE */
    @Column(name = "source_type", length = 20)
    private String sourceType;
    
    /** 源文件绝对路径 */
    @Column(name = "source_file_absolute_path", length = 1000)
    private String sourceFileAbsolutePath;
    
    /** 所属BUILD.gn文件路径 */
    @Column(name = "gn_file_path", nullable = false, length = 1000)
    private String gnFilePath;
    
    /** GN target名称 */
    @Column(name = "target_name", nullable = false, length = 500)
    private String targetName;
    
    /** 所属模块 */
    @Column(name = "module_name", length = 255)
    private String moduleName;
    
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
    }
}

